#include <stdio.h>

int max(int x[]) {
	int i, j, m;
	m = x[0];
	for (i = 1; i <= 3 - 1; i++)
		if (m < x[i])
			m = x[i];
	return m;
}

int min(int x[]) {
	int i, j, m;
	m = x[0];
	for (i = 1; i <= 3 - 1; i++)
		if (m > x[i])
			m = x[i];
	return m;
}

void sort(int x[][3]) {
	int i, j, k, t;
	for (j = 0; j <= 3 - 1; j++)
		for (i = 0; i <= 3 - 1 - 1; i++) {
			for (k = i + 1; k <= 3 - 1; k++)
				if (x[i][j] <= x[k][j]) {
					t = x[i][j];
					x[i][j] = x[k][j];
					x[k][j] = t;
				}
		}
}

int main() {
	int i, j, ma, mi, a[3][3] = {2, 6, 3, 7, 9, 1, 4, 5, 8};
	printf("before sortln");
	printf("\n");
	for (i = 0; i <= 2; i++) {
		for (j = 0; j <= 2; j++)
			printf("%4d", a[i][j]);
		printf("\n");
	}
	for (i = 0; i <= 3 - 1; i++) {
		ma = max(a[i]);
		mi = min(a[i]);
		printf("%d max:%2d min:%2d\n", i + 1, ma, mi);
	}
	sort(a);
	printf("\nafter sort\n");
	for (i = 0; i <= 2; i++) {
		for (j = 0; j <= 2; j++)
			printf("%4d", a[i][j]);
		printf("\n");
	}
	for (i = 0; i <= 3 - 1; i++) {
		ma = max(a[i]);
		mi = min(a[i]);
		printf("%d max:%2d min:%2d\n", i + 1, ma, mi);
	}
}
